Skip to content

feat(spec,service-analytics): a dataset answer says which records each measure counted, so a drill lists what the number counted - #30596

Merged
objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/project-thread-mg9ioh
Nov 5, 2026
Merged

objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/project-thread-mg9ioh

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Sales · project thread

domain:spec#2 · os-sales · session_01L6bhgXexAhb1ogpnymn5Jb
Fixes #30526

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 改了什么:数据集查询的回答多了一个可选字段 drillScopes,按度量说明“这个数字统计的是哪些记录”:数据集自己的筛选,加上度量自己的筛选,再加上被汇总的字段有值。
  • 为什么改:点开一个带筛选的数字(例如“已付款发票 2 张”)时,现在的下钻只按分组和组件筛选去列记录,会列出 4 张。客户端读不到数据集和度量的定义,所以只能由服务端在回答里告诉它。
  • 风险与回滚:只新增一个可选字段,不读它的客户端不受影响;查询算出的数字不变,唯一的行为改动是日期等占位符改为在查询入口解析一次,算数和下钻范围共用同一个时刻。回滚就是 revert 本 PR。
  • 先看:① packages/services/service-analytics/src/drill-scope.ts(什么算范围、什么时候不给);② packages/services/service-analytics/src/analytics-service.ts 里提前解析占位符和写 result.drillScopes 的两处;③ packages/spec/src/api/analytics.zod.ts 的字段说明。
  • 两分钟验证:pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dataset-drill-scopes.test.ts,预期 20 个测试全部通过,其中标着 CONTROL 的一条表明:不带范围时列出 4 条记录,而数字是 2。
  • 需要你做的:无,席位落地。

What changes

The precedent is drillRanges (#27074), and before it dimensionFields / drillRawRows (#20700). Those keys bound the clicked bucket. This PR adds the fifth drill sidecar, which bounds the clicked measure. It sits on the same answer and follows the same rule (ADR-0021 D2: the server states the drill bounds, and the client never restates dataset semantics).

  • @objectstack/spec: AnalyticsResult.drillScopes, optional, a map from measure name to FilterCondition, declared on the AnalyticsResultResponse wire schema too. Each selected measure name maps to the list filter on the answer's object that selects the records the measure aggregates. The filter is built from three parts:

    • the dataset's filter;
    • AND the measure's filter;
    • AND, for a measure over a field, { field: { $null: false } }, or both instants for a duration measure.

    Tokens are resolved as the query resolved them. The value is {} when no part applies. A measure is left out when no list filter can select its records, and a measure left out offers no drill (the [Decision] Dashboard numbers cannot be opened: should a tile lead to the records behind it? #30080 ruling, option A). That happens in three cases:

    • a derived measure;
    • a scope naming a relationship path (account.region as a key, or a dotted $field);
    • a filter that is not a condition object.

    A __compare column has no entry. drillScopes is set on every dataset answer that has rows. It is absent on a cube query answer and on a draft-preview answer.

  • @objectstack/service-analytics: queryDataset computes the scope in drill-scope.ts (measureDrillScopes, a pure function). It takes the token-resolved filters from before the dataset door's field binding, because the binding's minted member names are request-local and no record list knows them. resolveSelectionTokens is now exported and called once in answerDataset. The executor and the scope read the same resolved trees, and the executor's own call is then the identity. datasetMeasureSource finds what a measure aggregates the same way the queries did:

    • derived, bare or CUBE.-qualified;
    • duration, through durationMeasureIn;
    • declared, through scopedMeasureKey;
    • caller-minted, through mintCallerMeasures.
  • @object-ui/data-objectstack: queryDataset hand-picks the keys it returns, so it dropped any sidecar it did not list. This was measured before the change: the key never reached a widget. It now passes drillScopes through, typed as the spec slot.

  • Generated: content/docs/references/api/analytics.mdx (gen:docs, the one artifact check:generated proved stale). Ledger: packages/spec/dropped-refinements.baseline.json gains one site; see the Acceptance notes.

What each consumer must compose (not in this PR: #30080 and the ui card the seat files at landing)

A drill of a clicked number on measure M lists { $and: [bucket, widgetFilter, drillScopes[M]] } on object, leaving out any part that is absent:

Consumer bucket widgetFilter scope
Report drill (plugin-report dataset renderer) buildDatasetDrillFilter over dimensionFields + drillRawRows[i] + drillRanges[i] (a totals row: drillRawTotals[i][j]) the report's runtimeFilter drillScopes[M]
Chart / table widget drill (plugin-dashboard DatasetWidget) the same builder for the clicked row and series the widget's runtimeFilter drillScopes[M] of the clicked series
Dashboard tile click (#30080) none (a KPI has no dimensions) the tile's runtimeFilter drillScopes[M]

If drillScopes has no entry for M, the consumer offers no click. {} means "drillable, nothing to add", which is a different thing from a missing entry.

Why

A dataset number is computed under the dataset's filter, the measure's filter and the widget's runtimeFilter. A host that drills the number holds only the last one, and it has no read of the dataset definition. So every drill of a filtered measure listed a superset of what the number counted. On the showcase shape, the bucket listed 4 invoices behind paid_count 2. #30080 (the dashboard tile click, ruled option A) waits on this answer.

Tests

  • packages/services/service-analytics/src/__tests__/dataset-drill-scopes.test.ts (new, 20 tests):
    • Unit tier (mocked ObjectQL face), on the real producer shape (examples/app-showcase revenue-pulse: paid_count = count with filter: { status: 'paid' }, and paid_rate derived). Pins:
      • measure filter only;
      • dataset filter only, and both;
      • count over a field;
      • nested-relation form and a same-record $field kept;
      • tokens resolved to the caller, and the engine was handed the same value;
      • a cube-qualified name;
      • a dimensionless KPI carries the scope, and a zero-row answer carries none;
      • the scope is a deep copy;
      • contract vs wire: the real service's answer, through JSON.stringify, parsed by AnalyticsResultResponseSchema, keeps every scope.
    • Real-engine tier (ObjectQL + SqlDriver on SQLite, both faces, with and without a widget filter). Every count's composed drill (bucket ∧ widget ∧ scope) lists as many records as the number, and the sum adds up. Further pins:
      • a CONTROL pin: the bucket alone lists 4 against paid_count 2;
      • a duration measure, where the mean over the listed records equals the number;
      • a nested-relation dataset filter;
      • a dotted measure filter and a dotted dataset filter leave the scope out;
      • a CONTROL pin: engine.find refuses the dotted key with INVALID_FIELD.
  • packages/spec/src/api/analytics.test.ts: the response schema keeps each scope verbatim. It refuses these malformed values at data.drillScopes:
    • a string;
    • a list in an equality slot;
    • $and given an object;
    • an array map.
  • packages/spec/src/contracts/analytics-service.test.ts: a typed drillScopes read on the contract, plus a @ts-expect-error on a string scope.
  • ui/packages/data-objectstack/src/queryDataset.test.ts:
    • the passthrough keeps scopes verbatim, {} included;
    • absent stays undefined;
    • an array, a string or null is dropped;
    • a compile-time pin of identity with AnalyticsResult['drillScopes'].

Acceptance notes

  • Shape choices beyond the brief, each deliberate. Each one is pinned by a test above.
    1. The not-null leg for a measure over a field. Every aggregate skips an empty value (COUNT(field), Measure definitions are not fully compiled: aggregate: 'count' ignores field, and /api/v1/analytics/query drops every per-measure filter — the SQL is COUNT(*) for all of them #10298), so without the leg, count of total would list rows whose total is empty.
    2. A duration measure requires both instants.
    3. {} for a measure with nothing to add, so that "absent" keeps one meaning: no drill.
    4. Tokens are resolved once and shared by the numbers and the scope, so the two cannot straddle a period boundary. The error path is unchanged: every token refusal is a declared 400 that the catch rethrows either way.
    5. A caller-minted (undeclared) measure gets a scope too.
  • Relationship paths. The nested-relation form ({ account: { tier: 'gold' } }) is kept, because the record list serves it. A dotted path is left out, because the list refuses a dotted filter key. A later change could lower a one-hop dotted path to the nested form; this PR does not.
  • Ledger growth, a decision for the seat. dropped-refinements.baseline.json gains api/AnalyticsResultResponse → data.drillScopes.valueType.lazy. This is the same FilterConditionSchema lazy refinement already admitted at api/AnalyticsQueryRequest → where.lazy, and the spec build prints this entry. Header totals move 251 → 252 schemas and 1019 → 1020 sites.
  • Found, not fixed here (in the report):
    • The engine refuses the nested-relation form inside an aggregation's own filter ("the nested-relation form, which the engine serves in 'where' only"). So a dataset measure whose filter is { account: { tier: 'gold' } } fails the whole answer, even though the dataset schema accepts it. This was measured at the service on SQLite, not at the HTTP door.
    • data-objectstack also drops drillRawTotals. No ui code reads it today, so the gap is not felt.
  • Branch name. The branch is the harness-assigned claude/project-thread-mg9ioh, not claude/issue-30526-*, as amended on the claim.
  • Attribution link. It names this card thread, where the brief named the seat thread: the platform writes this thread's own link.
  • New lint warnings. eslint on data-objectstack adds 1 + 3 no-explicit-any warnings. These are (data as any) and test as any casts in the files' existing pattern; there are 0 errors.

Verification

Head ba62840b (branch base c23eafa8, origin/main f5aaa0bc merged in), under os-verify-lock, NODE_OPTIONS=--max-old-space-size=8192. Every count below is a VERDICT command-exit 0 unless it says otherwise. Every suite below ran twice, once at 25fc5696 before the merge and once at ba62840b after it, with the same counts both times.

  • pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated: 14 of 14 artifacts up to date, after gen:docs, which was the one artifact it proved stale. At the default 4096 MB heap, check:test-typecheck stops with "tsc failed without diagnostics", an out-of-memory error and not a verdict. At 8192 MB it passes: 52 files, 240 errors, all 131 pinned signatures held.
  • pnpm --filter @objectstack/spec test: Test Files 815 passed (815), Tests 25648 passed, 1 todo. pnpm --filter @objectstack/spec typecheck: exit 0.
  • @objectstack/service-analytics: test gives Test Files 211 passed (211), Tests 4996 passed, 300 skipped. typecheck: exit 0.
  • @object-ui/data-objectstack: test gives Test Files 115 passed (115), Tests 1319 passed. type-check: exit 0.
  • Consumers that git grep drillRanges lists: @object-ui/core 233 files passed (4376 tests), @object-ui/plugin-dashboard 202 files passed (1932 tests), @object-ui/plugin-report 33 files passed (307 tests).
  • eslint on the 10 changed source files: 0 errors (warnings as in Acceptance notes).
Ablation of the serving half (scripts/ablation-replace.mjs, restored to the HEAD blob bca6a0582f42)
  • Mutation: result.drillScopes = measureDrillScopes({ became void measureDrillScopes({ in analytics-service.ts. The anchor count went 1 → 0, and the blob went bca6a0582f42 → 98dc47836851.
  • dataset-drill-scopes.test.ts: 17 failed | 3 passed (20).
    • Every service pin went red on both tiers, the bucket CONTROL and the contract-vs-wire pin included.
    • The 3 that stayed green are the two direct walk tests and the record-list CONTROL (engine.find refuses a dotted key), none of which goes through the service.
  • Restore: the blob equals HEAD, and git diff HEAD is empty. The test imports the service from src, so no rebuild was needed.
Gates: dispatch-gates --commands, 110 derived at ba62840, 110 run, 0 NOT-MEASURED
  • node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran ran.list printed "110 derived famil(ies) accounted for — 110 run, 0 NOT-MEASURED (a DERIVED zero — all 110 recorded an exit code and none of them is 3)" and exited 0. Every line is exit 0.
  • On the first pass two gates exited 3 because built output was missing:
    • check:skill-examples lacked the client-react dist.
    • check:dual-build-cjs-loads lacked the dists of account, setup, studio, client-react, cloud-connection, connector-imap and connector-mcp.
    • After turbo run build of those 7 packages, both exit 0.
  • check-plugin-teardown-shape --self-test needed its pinned fixture commit 621a4876 fetched into the shallow clone first. The longest runs: check:type-check-debt 277 s, check:query-options-erasure 201 s, ui vitest run scripts/ 192 s.
  • No ! in the title and no (narrowing) arm, so there was no full dogfood run. CI owns the rest of the farm.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic (one optional field and its describe; the scope is computed in service-analytics).
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; eslint on the changed files has 0 errors (the full pnpm lint is the CI run).
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed.
  • 7. No hand edits to content/docs/references/ (regenerated by gen:docs), packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English (the 维护者速读 block excepted, per project convention).
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6bhgXexAhb1ogpnymn5Jb

…passed through by the adapter

The response schema and the AnalyticsResult contract carry `drillScopes`
(measure name -> FilterCondition on the answer's object); the spec pins
accept every scope verbatim and refuse a non-condition value. The
data-objectstack adapter hand-picks the keys it returns, so it now lists
`drillScopes` too, typed as the spec slot.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgXexAhb1ogpnymn5Jb
`pnpm --filter @objectstack/spec gen:docs`, the one artifact
`check:generated` proved stale.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6bhgXexAhb1ogpnymn5Jb
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/service-analytics, @objectstack/spec, touching 11 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/spec/dropped-refinements.baseline.json), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/client-sdk.mdx (via AnalyticsResult (symbol, a top-level interface))
  • content/docs/api/data-api.mdx (via AnalyticsResult (symbol, a top-level interface), AnalyticsResultResponseSchema (symbol, a top-level const))

⛔ 3 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-3.mdx (via AnalyticsResult (symbol, a top-level interface))
  • content/docs/releases/v17/17-6.mdx (via AnalyticsResult (symbol, a top-level interface))
  • content/docs/releases/v9.mdx (via AnalyticsResult (symbol, a top-level interface))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/spec/dropped-refinements.baseline.json) — pages documenting those are invisible to this run
  • the SDK route bridge reached 61 of 219 client-bound route-ledger rows — the other 158 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 158: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 103 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 170 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 739c972735d6feb9d1eea7be5d943cf340486fed → packageMentionDocs.

Which tree this was computed on

This run read content/docs from e9cbbb8b926f68aeabf7ef81c789daae730d0b21 — the merge of head ba62840b7d742525f60c41a225359ea3887b3a72 into base 739c972735d6feb9d1eea7be5d943cf340486fed, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e9cbbb8b926f68aeabf7ef81c789daae730d0b21 && git checkout e9cbbb8b926f68aeabf7ef81c789daae730d0b21
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 739c972735d6feb9d1eea7be5d943cf340486fed ba62840b7d742525f60c41a225359ea3887b3a72 && git checkout -B drift-repro 739c972735d6feb9d1eea7be5d943cf340486fed && git merge --no-ff ba62840b7d742525f60c41a225359ea3887b3a72

node scripts/docs-audit/affected-docs.mjs --json 739c972735d6feb9d1eea7be5d943cf340486fed

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 739c972735d6feb9d1eea7be5d943cf340486fed → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:spec#2 · os-sales · session_01L6bhgVugtCCwBs98FeR27P

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: ba62840b7d742525f60c41a225359ea3887b3a72
Local-runs: none
Scope: packages/spec/src/api/analytics.zod.ts, packages/spec/src/contracts/analytics-service.ts + packages/spec/src/api/analytics.test.ts (the compile-time schema-equals-contract pin, L50), packages/spec/src/data/filter.zod.ts (FilterConditionSchema, L2332-2351; $null, L1813), packages/spec/dropped-refinements.baseline.json, packages/services/service-analytics/src/drill-scope.ts, packages/services/service-analytics/src/analytics-service.ts (L3076, L3088-3125, L3261-3268, L4961-4973, L4847-4863, L4933-4950), packages/services/service-analytics/src/dataset-executor.ts (resolveSelectionTokens, L128-158; selection.measures, L567), packages/services/service-analytics/src/dataset-compiler.ts (L870, L902-903), packages/services/service-analytics/src/scoped-measure-key.ts, packages/services/service-analytics/src/dataset-filter-field-binding.ts (header), packages/services/service-analytics/src/index.ts (L38-39), packages/rest/src/analytics-routes.ts (L263-269), ui/packages/data-objectstack/src/index.ts (L7303-7314, L7481-7489), docs/adr/0021-analytics-dataset-semantic-layer.md (D2, Consequences), #30080 comment 6631202970, .changeset/30526-dataset-measure-drill-scopes.md, AGENTS.md (Post-Task Checklist step 3), scripts/check-changeset-no-major.mjs (level axis, L907-935, L1605-1606, L2052)

Inputs read: card #30526 body and all five comments (triage 6661303021, claim 6662301380, amendments 6662348690 / 6662348741, os-dev-report 6664363611); PR #30596 body, its 13-file list, and the net diff f5aaa0bc..ba62840b (merge-base of the head with main; the head is a merge commit whose own first-parent diff touches none of the hits); the check-runs on ba62840b. At the last poll: 38 success, 9 skipped, 0 failure, 19 still in progress (five Test Core shards, twelve Test UI shards, Type Check UI, Type Check workspace). Concluded and relevant here: Build Core, Check Changeset, Spec property liveness, Type Check source gates and consumer gates, Lint ESLint, Governed Surface Queue Guard, PR-body guards, Dogfood Regression Gate, Build & E2E UI, all success. No conclusion on this head is a failure. The in-progress ones remain the queue's gate, not this record's.

① Derived judgments

  1. Accept-set, wire — AnalyticsResultResponseSchema.data (analytics.zod.ts L254-268) gains an optional drillScopes: z.record(z.string(), FilterConditionSchema). data is a plain z.object, so before this head a served drillScopes was stripped on parse and after it it survives; every payload that parsed before still parses. A pure widening. Right. The refusals pinned in analytics.test.ts (a string scope, a list in an equality slot, $and given an object, an array map) are FilterConditionSchema's own and the record shape's; none narrows anything that parsed before.
  2. Public surface, contract — AnalyticsResult.drillScopes, an optional Record of measure name to FilterCondition (analytics-service.ts L339) on @objectstack/spec/contracts. Optional member; every existing implementer and reader compiles unchanged. The compile-time pin AnalyticsResultMatchesContract (an Assert of Eq between AnalyticsResultResponse['data'] and AnalyticsResult, analytics.test.ts L50) forces the schema and the contract to move together, and both moved. Right.
  3. Published JSON Schema — api/AnalyticsResultResponse gains data.drillScopes with additionalProperties = the FilterCondition projection minus its comparand superRefine (filter.zod.ts L2351), which z.toJSONSchema cannot emit. That is the one new ledger site, data.drillScopes.valueType.lazy; header totals 251 to 252 schemas and 1019 to 1020 sites match one new schema block carrying one site. Right (judged in ③ as the dev's open question).
  4. content/docs/references/api/analytics.mdx — one generated row. Generated output, not reviewed; its presence is what check:generated demands. Right.
  5. Service — queryDataset sets drillScopes on every rowful dataset answer on both faces (analytics-service.ts L3261-3268), from resolved.compiled (token-resolved, pre-binding); resolveSelectionTokens is now called once ahead of the executor (L3076) and exported from dataset-executor.ts. The package index (service-analytics src/index.ts L38-39) does not re-export it, so this is a package-internal export, not a public-surface change of @objectstack/service-analytics. The numbers are unchanged: the executor's own resolution over an already-resolved tree is the identity (the resolver allocates only when a placeholder was found, L147-157). Right.
  6. Adapter — ObjectStackAdapter.queryDataset (data-objectstack index.ts L7303-7314, L7481-7489) adds drillScopes?: AnalyticsResult['drillScopes'] to its return type and passes the map through when it is a non-array object. A public-surface widening of @object-ui/data-objectstack. Right. The REST door (analytics-routes.ts L269, res.json(result)) relays the result whole, and nothing else in packages/ or ui/packages/core hand-picks the sidecars (grep of dimensionFields / drillRawRows / drillRanges on the head, non-test), so the adapter was the only drop point.
  7. Metadata protocol — nothing an author writes changes: DatasetSchema, DatasetMeasureSchema and every authoring gate are untouched; the field is a response member only. Metadata-protocol: none. Right.
  8. Consumers — plugin-report and plugin-dashboard are untouched, as the claim's ⛔ list and the card's order ("[Decision] Dashboard numbers cannot be opened: should a tile lead to the records behind it? #30080 consumes it; the report / chart / table switch is a ui card the landing seat files") require. Right.

② Semver level

Changeset .changeset/30526-dataset-measure-drill-scopes.md: @objectstack/spec, @objectstack/service-analytics, @object-ui/data-objectstack, each patch; body carries Clause-②: yes (widening) and Metadata-protocol: none, bare and line-initial; the PR body carries the same two lines. Against AGENTS.md Post-Task Checklist step 3: "none takes patch" and "a non-protocol change, widening or breaking, ships patch" — a published API answer widened with no authorable change is exactly that. Against scripts/check-changeset-no-major.mjs's level axis (L907-935): a declared none must grade every introduced entry patch (all three are) and may move no authorable-surface/ or authorable-defaults/ baseline (the diff moves none; dropped-refinements.baseline.json is neither, L1605-1606); yes (widening) beside none is not one of the script's contradictions (added beside no, narrowed without (narrowing)). Every package whose published source the diff moves is named; @object-ui/data-objectstack is released through changesets (its CHANGELOG.md carries 18.3.0). Check Changeset on the head concluded success. Clause-②: yes (widening) — matches what the diff publishes; level patch on all three is right.

③ Boundary flags

Each flag from the os-dev-report (6664363611) and the PR body's Acceptance notes:

  • Shape 1, the not-null leg for a measure over a field — holds. dataset-compiler.ts L870 writes sql: m.field ?? '*', and every aggregate over a column skips an empty value, so the records a count/sum/avg/min/max/count_distinct over field read are exactly those where field holds a value; { field: { $null: false } } is the declared operator (filter.zod.ts L1813). Without the leg, count of total would list rows the number never counted. Accepted.
  • Shape 2, both instants for a duration measure — holds for the same reason; valueLegs (drill-scope.ts L95-104) emits one leg per instant. Accepted.
  • Shape 3, {} for a measure with nothing to add, absence meaning no drill — holds, and it is the ruling's shape: [Decision] Dashboard numbers cannot be opened: should a tile lead to the records behind it? #30080 (6631202970), "a tile whose dataset filter cannot be expressed as a list filter offers no click, rather than a list that does not match the number" needs one spelling for "no click", and this head gives absence that one meaning. The contract (analytics-service.ts L334-337) also states the map itself is {} when no selected measure has a scope; see ④ for the wire text.
  • Shape 4, tokens resolved once and shared — holds. resolveSelectionTokens (dataset-executor.ts L128-158) resolves the dataset filter, every measure filter, the runtime filter and each dateRange against one new Date(); the scope reads the same trees the executor was handed. Moving the call outside the try is behaviour-preserving: the catch (analytics-service.ts L3090-3125) rethrows anything that is not a missing-source error, and a token refusal is never one, so its path is identical. Accepted.
  • Shape 5, a caller-minted measure gets a scope — holds, and the mint cannot throw there: datasetMeasureSource (L4961-4973) reaches mintCallerMeasures([m]) only for a name neither declared, derived nor a duration, and the executor minted that same name at L2888 inside the try before the scope block runs, so any refusal (mintableMeasureKey, L4847-4863; inferMeasure) already fired. Accepted.
  • Relationship paths — nested form kept, dotted form left out: matches the ruling (left out means no click) and the record list's own refusal (INVALID_FIELD, pinned as CONTROL). A one-hop lowering is a later change, not owed here. Accepted.
  • Ledger growth (the open_questions entry) — answered: the row api/AnalyticsResultResponse → data.drillScopes.valueType.lazy is accepted. It is the same FilterConditionSchema (z.lazy + comparand superRefine, filter.zod.ts L2332-2351) the ledger already admits at api/AnalyticsQueryRequest where.lazy, api/DatasetSelection runtimeFilter.lazy, data/Query where.lazy and data/AnalyticsQuery where.lazy; the closed list in refinement-projection.ts has no arm for a comparand check, and adding one would move the projection of every FilterCondition slot at once, which the ledger's own description calls a public-contract decision and not a refactor. Teaching the list is outside this card. The build names the site in x-dropped-refinements, and the totals move by exactly one schema and one site.
  • Found, not fixed: the engine refuses the nested-relation form inside a measure's own filter while DatasetMeasureSchema accepts it — pre-existing, outside the hits and the claim's surface. Escalated to the seat: a card to file at landing (service-analytics / objectql, class c, with the dev's dedupe words).
  • Found, not fixed: the adapter also drops drillRawTotals — pre-existing, zero ui readers. Escalated to the seat as a line on the ui card the landing seat files.
  • Branch name claude/project-thread-mg9ioh — accepted by claim amendment 6662348690; no action.
  • Attribution link names the card thread — platform-written; no action.
  • New no-explicit-any warnings in data-objectstack — the file's existing (data as any) pattern, 0 errors, Lint · ESLint success; no action.
  • Deviation: the ablation sentence in the PR body — the body on the PR already carries the corrected wording ("the bucket CONTROL and the contract-vs-wire pin included ... the two direct walk tests and the record-list CONTROL"); nothing left to do.
  • check:test-typecheck needs an 8 GB heap — an environment note, not a verdict; CI's Type Check runs are the gate.

④ Design judgment

packages/spec/src/api/analytics.zod.ts (L254-268) against the ruling it implements and its first consumer. The shape is the one the card asked for ("the same vocabulary drillRanges uses"; a map from measure name to FilterCondition, the one filter vocabulary the dataset, the cube where and the record list all speak). I tried to break it on: a measure name that is an Object.prototype member (the service builds through a Map and Object.fromEntries, so it lands as an own property, and z.record reads own keys); a measure keyed by a cube-qualified spelling (the map is keyed by the selection's own spelling, which is how the answer's columns are keyed, executor L567, so the consumer's lookup is by the name it rendered); a filter whose values are Dates (structuredClone keeps them, res.json serialises them, the schema's comparand check reads ISO strings); a scope carrying a same-record $field comparand (objectql's filter path serves { $field } comparands, credential-evaluation-guard.ts L42, L122, having-filter.ts L79). The declared vocabulary holds. The sidecar's conditions (set only when rows exist, absent on cube and draft-preview answers) match the four sidecars beside it and the contract's shared preamble (L223-229). The $null: false leg and the nested-relation form are both declared FilterCondition spellings. No must-fix.

should-fix — packages/spec/src/api/analytics.zod.ts:254-268: the wire describe says "{} when none of these applies" of a measure's ENTRY, and "set on every dataset answer that has rows", but it never says the MAP itself may be {} (every selected measure left out, e.g. an answer whose only measures are derived). The contract text does (analytics-service.ts L334-337). A wire reader who must tell "absent" (not drillable at all) from "empty map" (present, no measure drillable) is the exact reader the ruling's "offers no click" depends on, and this text is the only one gen:docs publishes. One clause ("the map is {} when no selected measure has a scope") closes it; it can ride this PR or the ui card. Not a FAIL: the contract carries the sentence, and the parity pin keeps the two members typed identically.

packages/spec/src/contracts/analytics-service.ts (L223-229, L301-339) against ADR-0021 D2 and its first consumer. D2's literal text is drilldown on a report, "click a cell → underlying records (free, dataset-backed)", and the Consequences bullet "a tile can ... expand to underlying records natively"; the contract on main already reads D2 as "the server answers the drill bounds" for the four existing sidecars, and this member is the fifth in that reading, not a new reading. The scenario it is accepted against (the showcase paid_count 2 against a bucket of 4) is pinned at the real-engine tier, both faces, with and without a widget filter, and composed exactly as the doc comment prescribes (bucket AND runtimeFilter AND scope). I tried to break the "left out means no drill" rule: a dotted key or $field anywhere in the tree is caught by the walk (drill-scope.ts L80-92), a non-object filter is caught (L129), a derived measure is caught before any filter is read (L126), and a measure neither declared nor minted is undefined from datasetMeasureSource and left out; a duration measure's dotted instant and a measure field that is a relationship path (DatasetMeasureSchema L410-413 allows one) are both dotted legs and both caught. The doc states the three parts, the {} entry, the {} map, the excluded cases and the composition, and the typing (FilterCondition from data/filter.zod.js, already imported) is the schema's own z.ZodType output, so the pin at analytics.test.ts L50 holds. No finding.

should-fix — packages/services/service-analytics/src/__tests__/dataset-drill-scopes.test.ts:108-121 (coverage, outside the hits, read to judge the contract's "the record list serves it" claim for $field): the same-record $field reference is pinned only at the unit tier ("kept as written"); the real-engine tier pins no scope carrying $field against engine.find. The objectql read above says the list serves it, so no FAIL, but the claim the contract makes is one the test rig already has the means to measure.

Implemented-by: claude/project-thread-mg9ioh
Reviewed-by: session_01L6bhgVugtCCwBs98FeR27P

VERDICT: PASS


Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:spec#2 · os-sales · session_01L6bhgVugtCCwBs98FeR27P

维护者速读

  • 改了什么:数据集查询的回答多了一个可选字段 drillScopes,按度量说明“这个数字统计的是哪些记录”:数据集自己的筛选,加上度量自己的筛选,再加上被汇总的字段有值。
  • 为什么改:点开一个带筛选的数字(例如“已付款发票 2 张”)时,现在的下钻只按分组和组件筛选去列记录,会列出 4 张。客户端读不到数据集和度量的定义,所以只能由服务端在回答里告诉它。
  • 风险与回滚:只新增一个可选字段,不读它的客户端不受影响;查询算出的数字不变,唯一的行为改动是日期等占位符改为在查询入口解析一次,算数和下钻范围共用同一个时刻。回滚就是 revert 本 PR。
  • 先看:① packages/services/service-analytics/src/drill-scope.ts(什么算范围、什么时候不给);② packages/services/service-analytics/src/analytics-service.ts 里提前解析占位符和写 result.drillScopes 的两处;③ packages/spec/src/api/analytics.zod.ts 的字段说明。
  • 两分钟验证:pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dataset-drill-scopes.test.ts,预期 20 个测试全部通过,其中标着 CONTROL 的一条表明:不带范围时列出 4 条记录,而数字是 2。
  • 需要你做的:无,席位落地。
  • 席位意见:接受。契约面达档复核 PASS(comment 6664662638,Head-sha ba62840b),席位自读服务层与适配器的 diff,与卡的 ruling 一致;本 PR 只交协议和服务端,报表、图表、表格和仪表盘磁贴怎么用这个范围,留给 [Decision] Dashboard numbers cannot be opened: should a tile lead to the records behind it? #30080 和落地时开的 ui 卡。

席位核对

ACCEPT · head ba62840b7d742525f60c41a225359ea3887b3a72 · 2026-11-05T17:30Z

  1. 形态:draft,base main,正文第 5 行 Fixes #30526;全文闭合关键词只有这一处,没有挨着别的 open 卡号。13 个文件全在认领的文件面内(spec 答案槽和合同、service-analytics、data-objectstack 透传),没有 content/docs/releases/。
  2. 前提实测:在 merge-base f5aaa0bc 读到,数字在 dataset.filter ∧ measure.filter ∧ runtimeFilter 下算出,而答案的下钻 sidecar(dimensionFields / drillRawRows / drillRanges)只描述分组。前提成立。dev 的真引擎 CONTROL 也复现了:只按分组列出 4 条,paid_count 是 2。
  3. 门禁 check-runs(head ba62840b,席位本次读数):44 success、9 skipped、0 failure、13 in_progress(Test UI 分片、Test Core 分片、Type Check UI、Type Check · workspace)。在跑的这些就是入队闸门:全绿才 pr_ready + automerge_enable,有红按补丁轮处理。契约复核 6664662638 在 Served-tier: CONTRACT_REVIEW_TIER 下 PASS,Scope 覆盖 hits(analytics.zod.ts、contracts/analytics-service.ts)和所引代码。dev 本地另跑了 110 条派生门禁,--ran 0 NOT-MEASURED,这只证本地子集,不替代 check-runs。
  4. 席位自读(TIER_DEFAULT,hits 之外的部分):
    • drill-scope.ts:派生度量和未声明度量都不出现;点号键和点号 $field 用 namesRelationshipPath 排除;值腿 $null: false 只加在字段度量上,duration 加两腿,count(*) 不加;结果 structuredClone,用 Map 防原型键。
    • analytics-service.ts:resolveSelectionTokens 提前到 try 之外,只解析一次。范围取自 field binding 之前的 resolved.compiled,所以不带 minted 成员名。datasetMeasureSource 依次读派生、duration、声明的 cube 度量和调用方 mint,sql 就是编译器的 m.field ?? '*'(dataset-compiler.ts L870 附近)。
    • data-objectstack:只透传 map,不替每条范围做校验,符合注释的说法。
    • changeset 三包 patch,逐句核过:Clause-②: yes (widening) / Metadata-protocol: none 与 diff 一致(API 答案不是作者写的元数据)。“A measure left out offers no drill”“A __compare column has no entry”“queryDataset sets drillScopes on every dataset answer that has rows”三句与 measureDrillScopes 和 if (result.rows.length) 一致。“The adapter lists the keys it returns, so until now the sidecar was dropped”与适配器手挑键的返回语句一致。
  5. 接受的偏差:
    • 简报之外的三处形状细化:非空值腿、{} 与“不出现”区分、占位符共用一个时刻。三处都有 pin,复核 ③ 逐条接受。
    • dropped-refinements.baseline.json 新增位点 api/AnalyticsResultResponse data.drillScopes.valueType.lazy,与已入账的 AnalyticsQueryRequest where.lazy 是同一个 FilterConditionSchema lazy+superRefine,接受。
    • 正文消融段两行由席位按 dev 报告 deviations 代改(relay issue_patch,回读一致)。
    • 复核的两条 should-fix 不在本 PR 改:wire describe 没写整个 map 也可能是 {}(TS 合同 L334-337 已写),由 ui 卡写进“不出现即不能下钻”的读法;真引擎层没有 $field 范围的 pin,单元层已有,objectql 的 filter 路径也承接 $field。
  6. 范围外去向和 Skills-docs::
    • 种类是 none,没有 (narrowing),不欠 Skills-docs: 行。
    • dev 的 class c 发现:数据集接受嵌套关系形式的度量 filter,引擎在聚合 filter 里拒收。它是 main 上就有的,reach 只测到服务层,席位补 HTTP 入口实测后再决定立卡还是只留在 Acceptance notes。
    • data-objectstack 也丢了 drillRawTotals(零读者),写进落地时开的 ui 卡。
  7. 落地条款:check-governed-merges.mjs --pr 30596 答 NOT governed,786 行 ≤ 3000,属于 Tier S。全绿后经 relay pr_ready + automerge_enable,跟到 MERGED。同一动作里摘 pm:dispatched,开 ui 消费卡(report / chart·table / tile 各自组合“分组 ∧ 组件筛选 ∧ 范围”),并告知 [Decision] Dashboard numbers cannot be opened: should a tile lead to the records behind it? #30080。

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant